#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
int T, n;
int a[N];
ll tot;
bool vis[N];
ll judge(){
    ll ret = 0;
    for(int i = 2; i <= n; i++){
        for(int j = i - 1; j >= 1; j--){
            if(((vis[i] && vis[j]) || (!vis[i] && !vis[j])) && a[i] == a[j]){
                ret += (ll)(a[j]);
                break;
            }

        }
    }
    return ret;
}
void dfs(int x){
    if(x == n){
        tot = max(tot, judge());
    }
    for(int i = x; i <= n; i++){
        vis[x] = true;
        dfs(x + 1);
        vis[x] = false;
        dfs(x + 1);
    }
}
void init(){
    memset(a, 0, sizeof a);
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)scanf("%d", &a[i]);
    tot = 0;
    dfs(1);
}
int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    scanf("%d", &T);
    for(int i = 1; i <= T; i++){
        init();
        dfs(1);
        printf("%lld\n", tot);
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
